package com.example.toolproject.demo.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName DatabaseBackups
 * @Description TODO    数据库备份工具类
 * @Author lvyongwei
 * @Date 2020-05-29 13:25
 **/
@Component
public class DatabaseBackups {

    @Value("${wanle.profile}")
    private String filePath;

    @Value("${spring.datasource.username}")
    private String u;

    @Value("${spring.datasource.password}")
    private String p;

    private final String databaseName="wanlecinema";

    public String databasebackup(){
        try {
            Process process = Runtime.getRuntime().exec(
                    "cmd  /c  mysqldump -u "+u+" -p"+p+" " + databaseName + " > "
                            + filePath + "/" + databaseName + new java.util.Date().getTime()
                            + ".sql");
            //备份的数据库名字为teacher，数据库连接和密码均为root
            System.out.println("success!!!");
            return "success";
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "error";
        }
    }
}
